$(document).ready(function(){
	$('.tipsy').tipsy({gravity: 's'});// nw | n | ne | w | e | sw | s | se --- http://onehackoranother.com/projects/jquery/tipsy/
	$("#frmUpload").validate({
		errorClass		: 'errorMessage',
		errorElement	: 'div',
		onfocusout		: false,
		onkeyup			: false,
		rules: {
			palbumid: {
				albumRequired			: true
			},
			pname:{
				nameRequired			: true,
				nameMinlength			: true
			},
			pimage: {
				required				: true,
				validateImgFormat		: true,
				validateImgSize			: true
			}
		},
		messages: {	
			palbumid: {
				albumRequired			: album_required
			},
			pname:{
				nameRequired			: name_required,
				nameMinlength			: name_minlength
			},
			pimage: {
				required				: image_required,
				validateImgFormat		: image_format,
				validateImgSize			: image_size
			}
		},
		errorPlacement: function(label, element) {
			var id = element.attr('id');	
			label.insertAfter($('#' + id));			
		},
		submitHandler: function(form) {	
			form.submit();
		}
	});	
	$.validator.addMethod('albumRequired', function() {
		var strAlbumId = $('#palbumid').val();
		if(strAlbumId == "" || strAlbumId == 0) {
			return false;
		}
		return true;
	});
	$.validator.addMethod('nameRequired', function() {
		var strName 	= $('#pname').val();
		var intAblumbId = $('#palbumid').val();
		if(strName == undefined || intAblumbId > 0) {
			return true;
		} else {
			if(strName == "")
				return false;
			return true;
		}
	});
	$.validator.addMethod('nameMinlength', function() {
		var strName 	= $('#pname').val();
		var intAblumbId = $('#palbumid').val();
		if(strName == undefined || intAblumbId > 0) {
			return true;
		} else {
			if(strName.length < 5)
				return false;
			return true;
		}
	});
	$.validator.addMethod('validateImgFormat', function() {
		var strLinkImage = $('#pimage').val();
		if(strLinkImage == "") {
			return true;
		}
		return validateImage(strLinkImage);
	});
	$.validator.addMethod('validateImgSize', function() {
		var strLinkImage = $('#pimage').val();
		if(strLinkImage == "") {
			return true;
		}
		return validateImgSize("pimage");
	});
	
	
});
createAlbum = function(intValue) {
	if(intValue == -1) {
		$('#addAlbum').show();
	} else {
		$('#addAlbum').hide();
	}
}
function editAlbum(intAlbumId) {
	$.getJSON(				
		HOST_VFRIEND + 'ajax/album?act=3&albumid='+intAlbumId+'&callback=?',		
		function(response) {					
			var msg	= response['msg'];
			if(response['error'] == 0) {				
				$.blockUI({
					message: msg, 
					css: { 
						textAlgin:'left',
						background:'none',
						border: 'none',
						width:'300px', 
						top: (($(window).height()-300)/2) + 'px', 
						left:(($(window).width()-300)/2) + 'px',
						cursor: 'default'
					},
					overlayCSS: {
						textAlgin:'left',
						cursor: 'default'
					}
				});
			} else {
				alert(msg);
			}
		}
	);
}
function deleteAlbum(strAlbumId, strToken) {
	if(confirm(confirm_delete_album)) {
		document.location.href = HOST_VFRIEND + 'fullhouse/delalbum?albumid=' + strAlbumId + '&token=' + strToken;
	}
}
function pagingAlbum(intUserId, intAlbumId, intPage) {
	$('#loadImage').html('<div class="loading"><img src="'+HOST_STATICS+'img/bg/loading-bar.gif" alt="Loading album for photo" width="88" height="7" border="0" /><br/>'+loading+'</div>');
	$.getJSON(				
		HOST_VFRIEND + 'ajax/album?uid='+intUserId+'&albumid='+intAlbumId+'&apage='+intPage+'&callback=?',		
		function(response) {
			if(response['error'] == 0) {						
				$('#loadImage').html('');
				$('.cPage').html(intPage);
				$('#loadImage').html(response['msg']);
			} else {
				alert(response['msg']);
			}
		}
	);
}
function deleteImage(intImageId, intAlbumId) {
	if(confirm(confirm_delete_image) == true) {
		$('#loadImage').html('<div class="loading"><img src="'+HOST_STATICS+'img/bg/loading-bar.gif" alt="Loading album for photo" width="88" height="7" border="0" /><br/>'+loading+'</div>');
		$.getJSON(				
			HOST_VFRIEND + 'ajax/album?act=2&imgid='+intImageId+'&albumid='+intAlbumId+'&callback=?',		
			function(response) {					
				if(response['error'] == 0) {						
					showUIMessage(response['msg']);		
				} else {
					alert(response['msg']);
				}
				$('#loadImage').html('');
				var intPage 	= response['page'];
				var intTotal 	= response['total'];
				var strLink		= response['link'];
				if(intTotal == 0) {
					document.location.href = strLink;
				} else {
					$('#pAlbum').html('<em class="cPage">'+intPage+'</em>/'+intTotal);
					$('#loadImage').html(response['data']);
				}
				
			}
		);
	}	
}
function likeImage(intImageId) {	
	$.getJSON(				
		HOST_VFRIEND + 'ajax/album?act=1&imageid='+intImageId+'&callback=?',		
		function(response) {					
			if(response['error'] == 0) {						
				showUIMessage(response['msg']);
				$('#pLike').html(response['like']);
			} else {
				alert(response['msg']);
			}
		}
	);
}
function deleteCmt(intImageId,intVal,intPage) {	
	if(confirm(confirm_delete) == true) {
		$.getJSON(				
			HOST_VFRIEND + 'comment/pcmtsend?act=1&imageid='+intImageId+'&icommentid='+intVal+'&page='+intPage+'&callback=?',		
			function(response) {					
				if(response['error'] == 0) {						
					showUIMessage(response['msg']);
					$('#sComment').html(response['data']);
					$('#pCmt').html(response['total']);
				} else {
					alert(response['msg']);
				}
			}
		);
	} 
}
function likeCmt(intImageId,intVal,intPage) {	
	$.getJSON(				
		HOST_VFRIEND + 'comment/pcmtsend?act=2&imageid='+intImageId+'&icommentid='+intVal+'&page='+intPage+'&callback=?',		
		function(response) {					
			if(response['error'] == 0) {						
				showUIMessage(response['msg']);				
				$('#lcmt' + intVal).html(response['like']);
			} else {
				alert(response['msg']);
			}
		}
	);
}
onMouseOverForImg = function(intId) {
	$('#sAct' + intId).show();
}
onMouseOutForImg = function(intId) {
	$('#sAct' + intId).hide();
}
onMouseOverForCmt = function(intId) {
	$('#rowCmt' + intId).show();
}
onMouseOutForCmt = function(intId) {
	$('#rowCmt' + intId).hide();
}